package com.caiyi.financial.nirvana.sms.task;

import com.caiyi.financial.nirvana.sms.entity.SmsMsg;
import com.caiyi.financial.nirvana.sms.service.SmsMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Mario on 2017/12/21 0021.
 * 更新Msg任务
 */
public class UpdateMsgTask implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(UpdateMsgTask.class);

    private SmsMsgService smsMsgService;
    private SmsMsg smsMsg;

    /**
     * 构造函数
     *
     * @param smsMsgService service
     * @param smsMsg        smsMsg
     */
    public UpdateMsgTask(SmsMsgService smsMsgService, SmsMsg smsMsg) {
        this.smsMsg = smsMsg;
        this.smsMsgService = smsMsgService;
    }

    @Override
    public void run() {
        try {
            int count = this.smsMsgService.updateByMessageId(smsMsg);
            if (count == 0) {
                logger.warn("UpdateMsgTask error ! messageId : {}, status : {} ", smsMsg.getMessageId(), smsMsg.getStatus());
            }
        } catch (Exception e) {
            logger.error("UpdateMsgTask error !!! ", e);
        }
    }
}
